const App = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    ji_list:[],
    ji:1,
    ji_url:'',
    isLogin: false,
    // 文章详情
    detail: {},
    autoplay:true, //是否自动播放
    scrollHeight:null,//播放器高度
    menuMoreStatus:false,
    video_name:'',
    share_id:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      video_name:options.video_name,
      share_id:options.video_id,
      isLogin: App.checkIsLogin(),
    });

  },
  onShow(){
    this.setData({
      isLogin: App.checkIsLogin(),
    });
    if (this.data.isLogin) {
      // 获取文章详情
      this.getArticleDetail(this.data.share_id);
      this.setListHeight();
    }
  },
  /**
   * 获取文章详情
   */
  getArticleDetail(article_id) {
    let _this = this;
    App._get('video/gatherList', {
      video_id:article_id
    }, function (result) {
      let detail = result.data;
      _this.setData({
        ji_list:detail,
        ji_url:detail[0].video_url
      });
      //设置页面标题
      wx.setNavigationBarTitle({
        title:  _this.data.video_name
      })
    });
  },
   // 导航更多开关
   menuMore(e){
    console.log("menuMore",this.data.menuMoreStatus);
    let that = this;
    that.setData({
      menuMoreStatus: !that.data.menuMoreStatus
    }); 
  },
  // 选集播放
  onChangMenu(e){
    console.log(e.currentTarget.dataset.url)
    this.setData({
      ji: e.currentTarget.dataset.id,
      ji_url: e.currentTarget.dataset.url,
      menuMoreStatus:false
    }); 
    console.log(this.data.menuId)
    this.getList();
  },
 /**
   * 设置列表高度
   */
  setListHeight() {
    let systemInfo = wx.getSystemInfoSync(),
    rpx = systemInfo.windowWidth / 750, // 计算rpx
    tapHeight = Math.floor(rpx * 148), // tap高度
    scrollHeight = systemInfo.windowHeight - tapHeight;
    console.log("高度 =",systemInfo.windowHeight);
    this.setData({
      scrollHeight
    });
  },
  /**
   * 分享当前页面
   */
  onShareAppMessage() {
    // 构建页面参数
    const params = App.getShareUrlParams({
      'video_id': this.data.share_id
    });
    return {
      title: this.data.detail.article_title,
      path: "/pages/video/detail/index?" + params
    };
  },

  /**
   * 分享到朋友圈
   * 本接口为 Beta 版本，暂只在 Android 平台支持，详见分享到朋友圈 (Beta)
   * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
   */
  onShareTimeline() {
    // 构建页面参数
    const params = App.getShareUrlParams({
      'video_id': this.data.share_id
    });
    return {
      // title: this.data.detail.article_title,
      path: "/pages/video/detail/index?" + params
    };
  }

})